@extends('home.parent')
@section('title','新增管理员权限')
@section('head_js')
@endsection
@section('head_css')
<link rel="stylesheet" href="{{ asset('/css/select2/select2.min.css') }}">
@endsection
@section('content')
<div class="content-wrapper">
<section class="content-header">
    <h1>
        新增管理员权限
        <small></small>
    </h1>
    <ol class="breadcrumb">
        <li><a href="{{URL('admin')}}"><i class="fa fa-dashboard"></i> 首页</a></li>
        <li><a href="{{URL('admin/limit/list')}}">管理员权限列表</a></li>
        <li class="active">新增管理员权限</li>
    </ol>
</section>
<section class="content">
  <div class="row">
    <div class="col-md-6">
      <!-- general form elements -->
      <div class="box box-primary">
        <!--
        <div class="box-header with-border">
          <h3 class="box-title"></h3>
        </div>
        -->
        <!-- /.box-header -->
        <!-- form start -->
        @if(Session::has('error_msg'))
        <div class="callout callout-danger" id="login-box-msg" style="display:block;">
          <h4 id="show_error_msg">{{ session('error_msg') }}</h4>
        </div>
        @else
        <div class="callout callout-danger" id="login-box-msg" style="display:none;">
            <h4 id="show_error_msg"></h4>
        </div>
        @endif
        <form role="form" action="{{URL('admin/limit/create/save')}}" method="post" id="admin_limit_create_form">
          <div class="box-body">
            <div class="form-group">
              <label for="status">类型</label>
              <select class="form-control" id="status" name="status" style="width: 40%;">
                <option value="1">权限链接</option>
                <option value="2">权限菜单</option>
                <option value="0">关闭</option>
              </select>
            </div>
            <div class="form-group">
              <select class="form-control select2" style="width: 40%;" id="fid" name="fid">
                <option value="0">顶级</option>
                @foreach($menus as $menu)
                  <option value="{{ $menu['admin_limit_id'] }}">{{ $menu['limit_name'] }}</option>
                @endforeach
              </select>
            </div>
            <div class="form-group">
              <label for="limit_name">权限名</label>
              <input type="text" class="form-control" id="limit_name" name="limit_name" placeholder="请输入权限名" required>
            </div>
            <div class="form-group" id='limit_url_div'>
              <label for="limit_url">权限地址</label>
              <input type="text" class="form-control" id="limit_url" name="limit_url" placeholder="请输入权限地址">
            </div>
          </div>
          <!-- /.box-body -->
          <div class="box-footer">
            <button type="submit" class="btn btn-primary">提 交</button>
            <button type="button" class="btn btn-danger pull-right" onclick="history.go(-1)">取 消</button>
          </div>
        </form>
      </div>
    </div>
  </div>
</section>
</div>
@endsection
@section('foot_js')
<script src="{{ asset('/js/tools.js') }}"></script>
<script src="{{ asset('/css/select2/select2.full.min.js') }}"></script>
<script type="text/javascript">
$(document).ready(function(){
  $(".select2").select2();
  $('#status').change(function(){
    var status = $(this).val();
    if(status == 2){
      $('#limit_url_div').hide();
    }else{
      $('#limit_url_div').show();
    }
  })
  $('#admin_limit_create_form').submit(function(){
    var status  = $("#status").val();
    var limit_name  =  $.trim($("#limit_name").val());
    var limit_url  =  $.trim($("#limit_url").val());
    if(limit_name == ''){
      $('#show_error_msg').html('请输入权限名');
      $("#login-box-msg").show();
      return false;
    }
    if(status != 2){
      if(limit_url == ''){
        $('#show_error_msg').html('请输入权限地址');
        $("#login-box-msg").show();
        return false;
      }
      var url = "{{URL('admin/limit/valid/limiturl')}}";
      var data = {limit_url:limit_url};
      var is_success = puppet.myajax('post',url,data,false);
      if(is_success.code == true){
        $("#show_error_msg").html(is_success.message);
        $("#login-box-msg").show();
        return false;
      }
    }
    layer.msg('操作成功',{icon:6});
  })
})
</script>
@endsection